local jiewei = fk.CreateSkill {

  name = "joyex__jiewei",

  tags = {  },

}



jiewei:addEffect("viewas", {
  name = "joyex__jiewei",
  anim_type = "defensive",
  pattern = "nullification",
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Player.Equip
  end,
  view_as = function(self, player,cards)
    if #cards ~= 1 then return end
    local c = Fk:cloneCard("nullification")
    c.skillName = jiewei.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function (self, player)
    return #player.player_cards[Player.Equip] > 0
  end,
})

jiewei:addEffect(fk.TurnedOver, {
  name = "#joyex__jiewei_trigger",
  events = { fk.TurnedOver },
  anim_type = "control",
  mute = true,
  --jiewei,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("joyex__jiewei") and not player:isNude() and player.faceup
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForDiscard(player, 1, 1, true, "joyex__jiewei", true, ".", "#joyex__jiewei-discard", true)
    if #cards > 0 then
      event:setCostData(self, cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("joyex__jiewei")
    room:notifySkillInvoked(player, "joyex__jiewei", "control")
    room:throwCard(event:getCostData(self), jiewei.name, player, player)
    if player.dead then return false end
    local to = room:askForChooseToMoveCardInBoard(player, "#joyex__jiewei-choose", "joyex__jiewei", true)
    if #to == 2 then
      room:askForMoveCardInBoard(player, room:getPlayerById(to[1]), room:getPlayerById(to[2]), "joyex__jiewei")
    end
  end,
})

return jiewei